feat: Add health check HTTP endpoint for monitoring#61
Merged
Conversation
Adds HTTP health check server for remote monitoring from @aecs4u (PR #21). ## Endpoints ### GET /health Simple health check returning 200 OK if gateway is running. Useful for load balancer health checks. ### GET /status Detailed JSON status with metrics: ```json { "status": "healthy", "uptime_secs": 3600, "total_connections": 42, "active_connections": 3, "total_messages": 1234 } ``` ## Features ### HealthStats Shared statistics tracked across connections: - Start time (for uptime calculation) - Total connections (cumulative) - Active connections (current) - Total messages processed ### Usage ```rust use rustyclaw::gateway::health::{start_health_server, HealthStats, SharedHealthStats}; let stats = Arc::new(HealthStats::new()); // Start health server on separate port tokio::spawn(start_health_server( "127.0.0.1:8081", stats.clone(), cancel_token, )); // Increment stats in connection handler stats.total_connections.fetch_add(1, Ordering::Relaxed); stats.active_connections.fetch_add(1, Ordering::Relaxed); ``` ## Use Cases - Load balancer health checks - Uptime monitoring (Pingdom, UptimeRobot) - Metrics collection - Remote status inspection ## No New Dependencies Uses existing: tokio, serde_json, anyhow ## Attribution Original implementation by @aecs4u
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds HTTP health check server for remote monitoring from @aecs4u (PR #21).
Endpoints
GET /health
Simple health check returning
200 OKif gateway is running.GET /status
Detailed JSON status with metrics:
{ "status": "healthy", "uptime_secs": 3600, "total_connections": 42, "active_connections": 3, "total_messages": 1234 }HealthStats
Shared atomic counters tracked across connections:
start_time— Gateway start timestampuptime_secs()— Calculated uptimetotal_connections— Cumulative connection countactive_connections— Current live connectionstotal_messages— Messages processedUsage
Use Cases
No New Dependencies
Uses existing:
tokio,serde_json,anyhowAttribution
Original implementation by @aecs4u